/**
 * Copyright (c) 2024,  科泰集团教研团队
 * 版权所有，请勿侵权
 */
package com.ktjy.springboot_ch02.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.ZoneId;
import java.util.Date;

/**
 *
 * @author 科泰集团教研团队
 * @packageName com.ktjiaoyu.entity;
 * @fileName Page.java
 * @createTime 2024/10/01 13:00:57
 * @lastModify 2024/10/01 13:00:57
 * @version 1.0.0
 */
@Data
@TableName("sys_user")
public class SysUser implements Serializable {
    @TableId(type = IdType.AUTO)

    private Long id;  //主键ID
    private String account;  //账号

    @TableField("realName")
    private String realName;  //真实姓名

//    @JSONField(serialize = false)
    private String password;  //密码
    private Integer sex;  //性别（1:女、2:男）

//    @JSONField(format = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birthday;  //出生日期（年-月-日）
    private String phone;  //手机号码
    private String address;  //用户地址

    @TableField("roleId")
    private Long roleId;  //用户角色id

    @TableField("createdUserId")
    private Long createdUserId;  //创建人

    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createdTime;  //创建时间

    @TableField("updatedUserId")
    private Long updatedUserId;  //修改人

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedTime;  //修改时间

    @TableField("idPicPath")
    private String idPicPath;
    @TableField("workPicPath")
    private String workPicPath;

    public String getIdPicPath() {
        return idPicPath;
    }

    public void setIdPicPath(String idPicPath) {
        this.idPicPath = idPicPath;
    }

    public String getWorkPicPath() {
        return workPicPath;
    }

    public void setWorkPicPath(String workPicPath) {
        this.workPicPath = workPicPath;
    }

    //乐观锁版本号字段
    @Version
    private Integer version;

    private Boolean deleted;

    // 当前用户角色，须通过关联查询
//    private SysRole role;

    public int getAge(){
        if (this.birthday==null){
            return 0;
        }

        LocalDate birthLocalDate=birthday.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();

        LocalDate currentDate=LocalDate.now();
        return Period.between(birthLocalDate,currentDate).getYears();
    }


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }


    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }


    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }


    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }


    public Integer getSex() {
        return sex;
    }

    public void setSex(Integer sex) {
        this.sex = sex;
    }


    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }


    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }


    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }


    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }


    public Long getCreatedUserId() {
        return createdUserId;
    }

    public void setCreatedUserId(Long createdUserId) {
        this.createdUserId = createdUserId;
    }



    public Long getUpdatedUserId() {
        return updatedUserId;
    }

    public void setUpdatedUserId(Long updatedUserId) {
        this.updatedUserId = updatedUserId;
    }




//    public SysRole getRole() {
//        return role;
//    }
//
//    public void setRole(SysRole role) {
//        this.role = role;
//    }
}
